package com.zengqingfa.dubbo.mall.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.zengqingfa.dubbo.mall.entity.UserAddress;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @fileName: UserServiceImpl
 * @author: zengqf3
 * @date: 2021-4-12 14:58
 * @description:
 */
@Component   //@Component注解用来注册bean
@Service     //@Service注意要用dubbo的,不要jdk的,用来注册服务的
public class UserServiceImpl implements UserService {


    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000") })
    @Override
    public List<UserAddress> getUserAddressList(String userId) {
        List<UserAddress> addresses = new ArrayList<>();
        addresses.add(new UserAddress(1, "北京", "111", "130000000"));
        addresses.add(new UserAddress(2, "广州", "222", "150000000"));
        throw new RuntimeException("Exception to show hystrix enabled.");
       // return addresses;
    }
}
